package com.test.shiro.listener;

import javax.annotation.Resource;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;

import com.test.shiro.session.ShiroSessionRepository;
/**
 * shiro 会话 监听器
 * @author yaojinshan
 * @since 2017-09-15 14:11
 */
public class CustomSessionListener implements SessionListener {
	@Resource(name="redisShiroSessionRepository")
    private ShiroSessionRepository shiroSessionRepository;

    /**
     * 一个会话的生命周期开始
     */
    @Override
    public void onStart(Session session) {
        System.out.println("on start");
    }
    /**
     * 一个会话的生命周期结束
     */
    @Override
    public void onStop(Session session) {
        System.out.println("on stop");
    }
    /**
     * 一个会话的生命周期结束
     */									
    @Override
    public void onExpiration(Session session) {
        shiroSessionRepository.deleteSession(session.getId());
    }

}
